using Lean.Localization;
using TMPro;
using UnityEngine;

[ExecuteInEditMode]
[DisallowMultipleComponent]
[RequireComponent(typeof(TextMeshPro))]
public class LeanLocalizationTMPFont : LeanLocalizedBehaviour
{
	[Tooltip("If PhraseName couldn't be found, this font will be used")]
	public TMP_FontAsset FallbackFont;

	public override void UpdateTranslation(LeanTranslation translation)
	{
		TextMeshPro component = GetComponent<TextMeshPro>();
		if (translation != null)
		{
			component.font = (translation.Object as TMP_FontAsset);
		}
		else
		{
			component.font = FallbackFont;
		}
	}

	protected virtual void Awake()
	{
		if (FallbackFont == null)
		{
			TextMeshPro component = GetComponent<TextMeshPro>();
			FallbackFont = component.font;
		}
	}
}
